#!/usr/bin/python3

from tkinter import *

class Application(Frame):
    """Build the basic window frame template"""

    def __init__(self, master):
        super(Application, self).__init__(master)
        self.grid()#打开网格定位功能
        #self.varSausage=IntVar()
        self.varSausage=BooleanVar()#实现复选框的的选择与否的数据判断
        self.varPepp=IntVar()#实验表明，可以使用BooleanVar和IntVar
        self.create_widgets()#自定义函数

    def create_widgets(self):
        self.label1 = Label(self, text="What do you want on your pizza?")
        #label方法显示一段字符串
        self.label1.grid(row=0)#位置
        self.check1=Checkbutton(self,text='Sausage',variable=self.varSausage)
        self.check2=Checkbutton(self,text='Pepperoni',variable=self.varPepp)
        #复选框方法的使用，variable=self.varSausage的使用可实现点击按钮参数的
        #返回给self.varSausage，后面的函数根据这值来判断是否点击复选框，进行操作
        self.check1.grid(row=1)
        self.check2.grid(row=2)#复选框的定位
        self.button1 = Button(self, text='Order', command=self.display)
        #Button方法的使用，并实现按钮点击函数的处理.
        self.button1.grid(row=3)

    def display(self):#点击按钮，实现判断复选框的判断使用if(self.varSausage.get())
        #，并做出相应的动作,这里使用get()方法获取到的应该为Int或者Bool类型只有0、1
        """Event handler for the button"""
        if (self.varSausage.get()):
            print('You want sausage')
        if (self.varPepp.get()):
            print('You want pepperoni')

        if (not self.varSausage.get() and not self.varPepp.get()):
            #可以看出not的级别比and高
            print("You don't want anything on your pizza?")
        print('---------------')#进行隔开    


root = Tk()#对象实例化
root.title('Test Application window with label')#标题
root.geometry('300x100')#长窗口大小
app = Application(root)#框架的应用
app.mainloop()
